package com.ben.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    //跳转到登陆页面
    @RequestMapping("/jumplogin")
    public String jumpLogin() throws Exception {
        return "login";
    }

    //跳转到首页
    @RequestMapping("/main")
    public String jumpSuccess() throws Exception {
        return "main";
    }

    @RequestMapping("/login")
    public String login(HttpSession session, @RequestParam("username") String username, @RequestParam("pwd") String pwd) {
        session.setAttribute("user", username);
        return "main";
    }

    //退出登陆
    @RequestMapping("logout")
    public String logout(HttpSession session) throws Exception {
        // session 过期
        session.invalidate();
        return "login";
    }
}
